package com.wtp.wallpaper.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wtp.wallpaper.annotation.ReplaceURL;
import com.wtp.wallpaper.pojo.dto.TabDTO;
import com.wtp.wallpaper.pojo.dto.UserUploadDTO;
import com.wtp.wallpaper.pojo.entity.Picture;
import com.wtp.wallpaper.pojo.entity.Tabs;
import com.wtp.wallpaper.pojo.entity.UserUpload;
import com.wtp.wallpaper.pojo.query.PageQuery;
import com.wtp.wallpaper.pojo.result.Result;
import com.wtp.wallpaper.pojo.vo.TabVO;
import com.wtp.wallpaper.pojo.vo.UserUploadVO;
import com.wtp.wallpaper.service.UserUploadService;
import com.wtp.wallpaper.utils.PojoConvertUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Arrays;

@RestController
@RequestMapping("/admin/userUpload")
@Slf4j
public class UserUploadController {

    @Autowired
    private UserUploadService userUploadService;
    @ReplaceURL
    @GetMapping("/userUploadPage")
    public Result userUploadPage(@RequestParam(defaultValue = "1") int pageNum,
                                 @RequestParam(defaultValue = "5") int pageSize,
                                 String state){
        Page<UserUpload> page = userUploadService.lambdaQuery()
                .eq(state != null, UserUpload::getState, state)
                .page(new PageQuery(pageNum, pageSize).toMpPage());

        return Result.success(PojoConvertUtil.convert(page, UserUploadVO.class));
    }

    @PostMapping("/modifyOne")
    public Result modifyOnePicture(UserUploadDTO userUploadDTO) throws IOException {
        log.info("传来数据:{}",userUploadDTO);
        userUploadService.update(userUploadDTO);
        return Result.success();
    }

    @PostMapping("/removeByIds")
    public Result removeByIds(UserUploadDTO userUploadDTO){
        log.info("传来ids:{}",userUploadDTO);
        userUploadService.removeByIds(
                Arrays.asList(userUploadDTO.getRemoveIds()));
        return Result.success();
    }
}
